<template>
  <j-form-container :disabled="disabled">
    <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
      <a-row>
        <a-col :span="12">
          <a-form-model-item label="任务描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description">
            <a-textarea v-model="model.description" rows="4" placeholder="请输入任务描述" />
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachid">
            <j-upload v-model="model.attachid"></j-upload>
          </a-form-model-item>
        </a-col>
        <!-- <a-col :span="24">
            <a-form-model-item label="parentid" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="parentid">
              <a-input v-model="model.parentid" placeholder="请输入parentid"></a-input>
            </a-form-model-item>
          </a-col> -->
      </a-row>
    </a-form-model>
  </j-form-container>
</template>
<script>
import { getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import JFormContainer from '@/components/jeecg/JFormContainer'
import { VALIDATE_FAILED } from '@/components/jeecg/JVxeTable/utils/vxeUtils.js'
export default {
  name: 'ProjecttaskitemForm',
  components: {
    JFormContainer
  },
  props: {
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data () {
    return {
      model: {
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      validatorRules: {
      },
      confirmLoading: false,
    }
  },
  created () {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    initFormData (url, id) {
      this.clearFormData()
      if (!id) {
        this.edit(this.modelDefault)
      } else {
        getAction(url, { id: id }).then(res => {
          if (res.success) {
            let records = res.result
            if (records && records.length > 0) {
              this.edit(records[0])
            }
          }
        })
      }
    },
    edit (record) {
      this.model = Object.assign({}, record)
    },
    getFormData () {
      let formdata_arr = []
      this.$refs.form.validate(valid => {
        if (valid) {
          let isNullObj = true
          Object.keys(this.model).forEach(key => {
            if (this.model[key]) {
              isNullObj = false
            }
          })
          if (!isNullObj) {
            formdata_arr.push(this.model)
          }
        } else {
          this.$emit("validateError", "任务分类描述表单校验未通过");
        }
      })
      return formdata_arr;
    },
    validate (index) {
      return new Promise((resolve, reject) => {
        // 验证主表表单
        this.$refs.form.validate(valid => {
          !valid ? reject({ error: VALIDATE_FAILED, index }) : resolve()
        })
      }).then(values => {
        return Promise.resolve()
      }).catch(error => {
        return Promise.reject(error)
      })

    },
    clearFormData () {
      this.$refs.form.clearValidate()
    },
  }
}
</script>
